package com.iseastar.guojiang.register;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.guojiang.dialog.DialogMgr;
import com.iseastar.guojiang.model.RegisterCourierMaterialBean;
import com.shouhuobao.station.R;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.GlideUtil;

/**
 * 注册物料点击大图
 * Created by lidandan on 2018/4/28.
 */

public class RegisterCourierMaterialAdapter extends BaseAdapterExt<RegisterCourierMaterialBean.MaterialBean> {
    public RegisterCourierMaterialAdapter(ArrayList<RegisterCourierMaterialBean.MaterialBean> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.register_courier_material_adapter, parent, false);
            holder = new ViewHolder();
            holder.mPhotoImageView = (ImageView) convertView.findViewById(R.id.photo_image_view);
            holder.mMaterialTitleTV = (TextView) convertView.findViewById(R.id.material_title_tv);
            holder.mMaterialContentTV = (TextView) convertView.findViewById(R.id.material_content_tv);
            convertView.setTag(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final RegisterCourierMaterialBean.MaterialBean item = getItem(position);
        GlideUtil.loadImage(context, item.getImage(), 0, holder.mPhotoImageView);
        holder.mMaterialTitleTV.setText(item.getName());
        holder.mMaterialContentTV.setText(item.getDescription());
        holder.mPhotoImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.getImages() != null && item.getImages().size() > 0) {
                    DialogMgr.registerPhotoViewPager(context, item.getImages());
                }
            }
        });
        return convertView;
    }

    class ViewHolder {
        private ImageView mPhotoImageView;
        private TextView mMaterialTitleTV;
        private TextView mMaterialContentTV;
    }
}
